package com.quick.controller;

import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.quick.base.KeyValue;
import com.quick.base.Page;
import com.quick.base.Search;
import com.quick.service.ISysDictService;
import com.quick.sys.domain.dto.SysDictDTO;
import com.quick.sys.domain.search.SysDictSearch;
import com.quick.sys.domain.vo.SysDictVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;

@RestController
@RequestMapping("api/sys/dict")
@Api(tags ="字典管理")
@AllArgsConstructor
public class SysDictController {
	
	private final ISysDictService sysDictService;
	
	@PostMapping("serach")
	@ApiOperation(value = "分页查询")
	public Page<SysDictVo> serach(@RequestBody Search<SysDictSearch> search){
		return sysDictService.searchDict(search);
	}
	
	@PostMapping("add")
	@ApiOperation(value = "新增")
	public Boolean add(@RequestBody SysDictDTO dict) {
		return sysDictService.saveDict(dict);
	}
	
	@GetMapping("query/{id}")
	@ApiOperation(value = "查询")
	public SysDictVo query(@PathVariable("id") Integer id) {
		return sysDictService.queryDict(id);
	}
	
	@GetMapping("del/{id}")
	@ApiOperation(value = "删除")
	public Boolean del(@PathVariable("id") Integer id) {
		return sysDictService.delDict(id);
	}
	
	@ApiOperation("全部")
	@GetMapping("all")
	public  Map<String, List<KeyValue>> all(){
		return sysDictService.all();
	}

}
